package com.ruoyi.weiriya.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.WVehicle;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.weiriya.domain.WDoor;
import com.ruoyi.weiriya.mapper.WDoorMapper;
import com.ruoyi.weiriya.service.IWCompanyService;
import com.ruoyi.weiriya.service.IWDoorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 门禁列Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-08-24
 */
@Service
public class WDoorServiceImpl extends ServiceImpl<WDoorMapper, WDoor> implements IWDoorService
{

    @Autowired
    private WDoorMapper doorMapper;
    @Autowired
    private IWCompanyService companyService;

    @Override
    public List<WDoor> getList(WDoor wDoor) {
        QueryWrapper<WDoor> queryWrapper = wDoor.queryWrapper();
        if (StringUtils.isNotBlank(SecurityUtils.getLoginUser().getUser().getCompanyId())) {
            List<String> areaIdListByUserId = companyService.getAreaIdList();
            if (areaIdListByUserId.size() > 0) {
                queryWrapper.in("d.area_id", areaIdListByUserId);
            } else {
                return new ArrayList<>();
            }
        }

        return doorMapper.getList(queryWrapper);
    }

    @Override
    public WDoor getWDoorById(String id) {
        return doorMapper.getWDoorById(id);
    }
}
